package org.wanho.rent.service.proxy;

import java.util.List;

import org.wanho.jdbc.transaction.TransactionManager;
import org.wanho.rent.entity.ProductType;
import org.wanho.rent.exception.ServiceException;
import org.wanho.rent.factory.ObjectFactory;
import org.wanho.rent.service.ProductTypeService;
import org.wanho.rent.util.PageInfo;

public class ProductTypeServiceProxy implements ProductTypeService{
	
	private TransactionManager tx = (TransactionManager) ObjectFactory.getObject("tx");
	private ProductTypeService productTypeService = (ProductTypeService) ObjectFactory.getObject("productTypeService");

	@Override
	public PageInfo<ProductType> findByPage(int pageNo, int pageSize) {
		try {
			tx.beginTransaction();
			PageInfo<ProductType> pageInfo = productTypeService.findByPage(pageNo, pageSize);
			tx.commit();
			return pageInfo;
		} catch (Exception e) {
			tx.rollback();
			throw new ServiceException(e.getMessage());
		}
	}

	@Override
	public List<ProductType> findAll() {
		try {
			tx.beginTransaction();
			List<ProductType> list = productTypeService.findAll();
			tx.commit();
			return list;
		} catch (Exception e) {
			tx.rollback();
			throw new ServiceException(e.getMessage());
		}
	}

}
